package com.jctrip.hotel.management.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jctrip.hotel.domain.dao.HtOrderRouteRecordDao;
import com.jctrip.hotel.domain.dao.HtOrderSourceRecordDao;
import com.jctrip.hotel.domain.entity.HtOrderRouteRecord;
import com.jctrip.hotel.domain.entity.HtOrderSourceRecord;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @Author: zxy
 * @CreateTime: 2023-09-11 19:35
 * @Description:
 */
@Service
@Slf4j
public class InfoService {
    @Autowired
    private HtOrderRouteRecordDao htOrderRouteRecordDao;

    @Autowired
    private HtOrderSourceRecordDao htOrderSourceRecordDao;

    public List<String> getHotels() {
        List<String> orders = Optional.ofNullable(htOrderRouteRecordDao.selectList(
                new LambdaQueryWrapper<HtOrderRouteRecord>()
                        .eq(HtOrderRouteRecord::getRouteId, "jcdlt")
                        .ge(HtOrderRouteRecord::getOrderCreateTime, DateUtils.addDays(new Date(), -1))))
                .orElse(new ArrayList<>()).stream().map(HtOrderRouteRecord::getOrderId)
                .collect(Collectors.toList());

        return new ArrayList<>(Optional.ofNullable(htOrderSourceRecordDao.selectList(
                new LambdaQueryWrapper<HtOrderSourceRecord>()
                        .in(HtOrderSourceRecord::getOrderId, orders)))
                .orElse(new ArrayList<>())
                .stream()
                .map(HtOrderSourceRecord::getHotelId)
                .collect(Collectors.toSet()));
    }
}
